/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.huiruan.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.huiruan.entity.TStock;
import com.huiruan.service.TStockService;

import com.huiruan.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 *
 *
 * @author czl
 * @date 2022-05-05 15:17:11
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/tstock" )
@Tag(name = "用户管理", description = "用户相关接口")//swagger配置
//http://localhost:8081/api/swagger-ui/index.html
public class TStockController {

    private final TStockService tStockService;
    /**
     * 分页查询
     * @param page 分页对象
     * @param tStock
     * @return
     */
    //@ApiOperation(value = "分页查询", notes = "分页查询")
    @Operation(summary = "分页查询", description = "返回所有用户数据")

    @GetMapping("/page" )
    //@PreAuthorize("@pms.hasPermission('midms_tstock_get')" )
    public Result getTStockPage(Page page, TStock tStock) {
        return Result.success(tStockService.page(page, Wrappers.query(tStock)));
    }


    /**
     * 通过id查询
     * @param code id
     * @return R
     */
    @Operation(summary = "通过id查询", description = "返回所有用户数据")
    @GetMapping("/{code}" )
    public Result getById(@PathVariable("code" ) String code) {
        return Result.success(tStockService.getById(code));
    }

    /**
     * 新增
     * @param tStock
     * @return R
     */
    @Operation(summary = "新增", description = "新增")
    @PostMapping
    public Result save(@RequestBody TStock tStock) {
        return Result.success(tStockService.save(tStock));
    }

    /**
     * 修改
     * @param tStock
     * @return R
     */
    @Operation(summary = "修改", description = "修改")
    @PutMapping
    public Result updateById(@RequestBody TStock tStock) {
        return Result.success(tStockService.updateById(tStock));
    }

    /**
     * 通过id删除
     * @param code id
     * @return R
     */
    //@ApiOperation(value = "通过id删除", notes = "通过id删除")
    @Operation(summary = "通过id删除", description = "通过id删除")
    @DeleteMapping("/{id}" )
    public Result removeById(@PathVariable Long id) {
        return Result.success(tStockService.removeById(id));
    }

}
